package nz.ac.vuw.ecs.kcassell.geometry;

/**
 * This rectangle is defined via two points, the lower left (x1, y1) and the
 * upper right (x2, y2) corners. The rectangle is assumed to have its sides
 * parallel to the X and Y axes
 * 
 * @author Keith
 * 
 */
public class RectangleD {
	double x1 = 0.0;
	double y1 = 0.0;
	double x2 = 0.0;
	double y2 = 0.0;

	/**
	 * @param x1
	 * @param y1
	 * @param x2
	 * @param y2
	 */
	public RectangleD(double x1, double y1, double x2, double y2) {
		super();
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}

	public double area() {
		double area = Math.abs(x1 - x2) * Math.abs(y1 - y2);
		return area;
	}

	public double perimeter() {
		double perimeter = 2 * Math.abs(x1 - x2) + 2 * Math.abs(y1 - y2);
		return perimeter;
	}

	public double diagonalLength() {
		double side1 = Math.abs(x1 - x2);
		double side2 = Math.abs(y1 - y2);
		double diag = Math.sqrt(side1 * side1 + side2 * side2);
		return diag;
	}

	public double shortestSideLength() {
		double longest = Math.min(Math.abs(x1 - x2), Math.abs(y1 - y2));
		return longest;
	}

	public double longestSideLength() {
		double longest = Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2));
		return longest;
	}
}
